package com.sxt.quartz.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.JobDetailFactoryBean;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.scheduling.quartz.SimpleTriggerFactoryBean;

import com.sxt.quartz.jobs.QuartzJob;
/**
 * 简单Quartz配置类
 * @author Administrator
 *
 */
//@Configuration
public class QuartzConfig {
	/**
	 * 1.创建Job对象
	 */
	@Bean
	public JobDetailFactoryBean jobDetailFactoryBean() {
		JobDetailFactoryBean factory = new JobDetailFactoryBean();
		//关联Job类
		factory.setJobClass(QuartzJob.class);
		return factory;
	}
	/**
	 * 2.创建Trigger对象（简单Trigger）
	 */
	@Bean
	public SimpleTriggerFactoryBean simpleTriggerFactoryBean(JobDetailFactoryBean jobDetailFactoryBean) {
		SimpleTriggerFactoryBean factory = new SimpleTriggerFactoryBean();
		//关联JobDetail对象
		factory.setJobDetail(jobDetailFactoryBean.getObject());
		//该参数表示执行的毫秒数
		factory.setRepeatInterval(2000);
		//表示重复次数
		factory.setRepeatCount(5);
		return factory;
	}
	/**
	 * 3.创建Schedule对象
	 */
	@Bean
	public SchedulerFactoryBean schedulerFactoryBean(SimpleTriggerFactoryBean simpleTriggerFactoryBean){
		SchedulerFactoryBean factory = new SchedulerFactoryBean();
		//关联Trigger
		factory.setTriggers(simpleTriggerFactoryBean.getObject());
		return factory;
	}
}
